using Gateway.Api.Infrastructures;
using HotChocolate.Fusion.Clients;
using HotChocolate.Fusion.Composition;
using HotChocolate.Skimmed.Serialization;

var builder = WebApplication.CreateBuilder(args);
var microservices = await Microservices.CreateAsync();
var fusionGraph = await new FusionGraphComposer().ComposeAsync(
    new[]
    {
        microservices.Products.ToConfiguration(),
        microservices.Orders.ToConfiguration()
    });
builder.Services.AddHttpClient("DefaultClient");
builder.Services.AddSingleton<IWebSocketConnectionFactory, MicroserviceWebSocketConnectionFactory>();

builder.Services
    .AddFusionGatewayServer(SchemaFormatter.FormatAsString(fusionGraph));

var app = builder.Build();
app.MapGraphQL();
app.Run();